<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="../../common/assets_header.jsp"/>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<script src="<%=request.getContextPath()%>/assets/js/date-time/bootstrap-datepicker.min.js"></script>
<script src="<%=request.getContextPath()%>/assets/js/jqGrid/jquery.jqGrid.min.js"></script>
<script src="<%=request.getContextPath()%>/assets/js/jqGrid/i18n/grid.locale-en.js"></script>
<script>


jQuery(document).ready(function() {    
	
	loadGird();
	  
	
});

//初始化列表
function loadGird(){
	var grid_selector = "#grid-table";//列表对象
	var pager_selector = "#grid-pager";//列表分页对象
	jQuery(grid_selector).jqGrid({
		url : "<%=request.getContextPath()%>/module/role/list_json",
		datatype : "json",
		height: 300,
		colNames:[/*' ',*/ ' ','角色名','备注','模块名称','创建时间'],
		colModel:[
		{name:'moduleRoleId',index:'moduleRoleId', width:60, sorttype:"int", hidden: true},
		{name:'roleName',index:'roleName',width:90,sortable:false},
		{name:'roleDesc',index:'roleDesc', width:90,sortable:false},
		{name:'moduleName',index:'moduleName', width:90,sortable:false},
		{name:'createTime',index:'createTime', width:90,sortable:false}
		], 
		viewrecords : true,
		rowNum:10,	
		
		rowList:[10,20,30],
		pager : pager_selector,
		altRows: true,
		multiselect: false,
		 multiboxonly: true,
		 loadComplete : function() {
			},
		caption: "ModuleRole List",
		autowidth: true
	});
}

function delUser(){
	 var id = $("#grid-table").jqGrid('getGridParam', 'selrow');
	 var obj = null;
	 if(id){
		 obj = $("#grid-table").jqGrid('getRowData', id);
	 }else{
		 bootbox.alert({  
	            buttons: {  
	               ok: {label: '确认',className: 'btn-ok'  }  
	            },  
	            message: '请选择一行数据.',  
	            title: "提示",  
	        });
		 return;
	}
	 var susername = obj.roleName;
	 var id = obj.moduleRoleId;
	bootbox.dialog({
		message : "<spring:message code="sure you want to delete"></spring:message>"+susername+"<spring:message code="what"></spring:message>",
		title : "<spring:message code="delete the user"></spring:message>",
		buttons : {
			confirm : {
				label : '<spring:message code="sure to delete"></spring:message>',
				className : "btn red btn-ok",
				callback : function() {
					$.ajax({
						type : "GET",
						url : "<%=request.getContextPath()%>/module/role/del?id="+id,
						dataType : 'text',
						async : false,
						success : function(data) {
							if(data=="success"){
								$("#grid-table").trigger("reloadGrid"); 
							}else{
								noty({layout: 'center',text: "<spring:message code="delete the user failure"></spring:message>！",type: 'error', timeout: 2000 });
							}
						},
						error : function(data, status) {
							noty({layout: 'center',text: "<spring:message code="error"></spring:message>！",type: 'error', timeout: 2000 });
						}
					});
				}
			},
			cancel : {
				label : "<spring:message code="cancel"></spring:message>",
				className : "btn btn-danger"
			}
		}
	});
}

function add(){
	location.href="<%=request.getContextPath()%>/module/role/form";
}
function edit(){
	var id = $("#grid-table").jqGrid('getGridParam', 'selrow');
	 var obj = null;
	 if(id){
		 obj = $("#grid-table").jqGrid('getRowData', id);
		 location.href="<%=request.getContextPath()%>/module/role/form?id="+obj.moduleRoleId;
	 }
	
}


function search(){
	var val = $("#searchId").val();
	var searchValueInfoval = $("#searchValueInfo").val();
    var postData = $("#grid-table").jqGrid("getGridParam", "postData");
    $.extend(postData, {"searchValue":val,"searchValueInfo":searchValueInfoval});
	$("#grid-table").trigger("reloadGrid");
}


function rolePur(){
	var id = $("#grid-table").jqGrid('getGridParam', 'selrow');
	 var obj = null;
	 if(id){
		 obj = $("#grid-table").jqGrid('getRowData', id);
		 location.href="<%=request.getContextPath()%>/module/role/purview?id="+obj.moduleRoleId;
	 }
	

}


<%-- jQuery(document).ready(function() {    
	//排序
	if("${list.sort}"=="asc"){
	   if("${list.orderBy}"=="create_time"){
		   $("#th_createtime").attr("class","sorting_asc");
	   }
   }
	if("${list.sort}"=="desc"){
	   if("${list.orderBy}"=="create_time"){
		   $("#th_createtime").attr("class","sorting_desc");
	   }
   }
});

//查询
function sortBy(obj,field){
	var cls = $(obj).attr("class");
	$("#sorting_column_order").val(field);
	if(cls=="sorting"){
		$("#sorting_asc_desc").val("asc");
	}else if(cls=="sorting_asc"){
		$("#sorting_asc_desc").val("desc");
	}else if(cls=="sorting_desc"){
		$("#sorting_asc_desc").val("asc");
	}
	
	$("#list_form").submit();
}

//删除
function delRole(id,module_name){
	bootbox.dialog({
		message : "<spring:message code="sure you want to delete"></spring:message>"+module_name+"<spring:message code="what"></spring:message>",
		title : "删除企业应用",
		buttons : {
			confirm : {
				label : '<spring:message code="sure to delete"></spring:message>',
				className : "btn red btn-ok",
				callback : function() {
					$.ajax({
						type : "GET",
						url : "<%=request.getContextPath()%>/module/role/del?id="+id,
						dataType : 'text',
						async : false,
						success : function(data) {
							if(data=="success"){
								noty({layout: 'top',text: "删除成功！",type: 'success', timeout: 2000 });
								setTimeout(function(){window.location.reload();}, 1000);
							}else{
								noty({layout: 'top',text: "删除失败！",type: 'error', timeout: 2000 });
							}
						},
						error : function(data, status) {
							noty({layout: 'top',text: "<spring:message code="error"></spring:message>！",type: 'error', timeout: 2000 });
						}
					});
				}
			},
			cancel : {
				label : "<spring:message code="cancel"></spring:message>",
				className : "btn btn-danger"
			}
		}
	});
}



//编辑
function toEditPage(id){
	$("#list_form").attr("action","<%=request.getContextPath() %>/module/role/form");
	$("#hiddenId").val(id);
	$("#list_form").submit();
}

//分页
function toListPage(pageIndex){
	$("#list_form").attr("action","<%=request.getContextPath() %>/module/role/list");
	$("#iDisplayStart").val(pageIndex);
	$("#list_form").submit();
}
 --%>
</script>

</head>
<body >
		
		<%-- <form id="list_form" action="<%=request.getContextPath() %>/module/role/list" method="post">
		<input type="hidden" name="sorting_column_order" id="sorting_column_order" value="${list.orderBy }"/>
		<input type="hidden" name="sorting_asc_desc"  id="sorting_asc_desc" value="${list.sort}"/>
		<input type="hidden" name="id" id="hiddenId"></input>
		<input type="hidden" name="roleName" id="rolenameId"></input>
		<input type="hidden" name="iDisplayStart" id="iDisplayStart" value=${list.currentPage } />
		<div class="page-content">


			<!-- BEGIN PAGE CONTAINER-->

			<div class="container-fluid">

				<!-- BEGIN PAGE HEADER-->

				<div class="row-fluid">

					<div class="span12">
						
					
						<h3 class="page-title">

							<!--系统用户管理 <small>欢迎您，admin!</small> -->

						</h3> 

						<ul class="breadcrumb">

							<li>

								<i class="icon-home"></i>

								<a href="index.html">Home</a> 

								<i class="icon-angle-right"></i>

							</li>

							<li>

								<a href="#">系统管理</a>

								<i class="icon-angle-right"></i>

							</li>

							<li><a href="#">角色管理</a></li>

						</ul>

						

					</div>

				</div>

				<!-- END PAGE HEADER-->

				<!-- BEGIN PAGE CONTENT-->

				<div class="row-fluid">
							<!-- BEGIN EXAMPLE TABLE PORTLET-->
					
							<div class="portlet-body">

								<div class="clearfix">

									<p class="pull-left">
										
										<a href="#" onclick="toEditPage(null);" class="btn blue" >

										<spring:message code="btn.common.add.role"></spring:message><i class="icon-plus"></i>

										</a>
									</p>

								</div>
																								
							<!-- 	<div class="control-group input-append hidden-phone"> -->
								<div class="control-group "> 
									
									模块名称:
									<div class="input-append hidden-phone">
									
											<select tabindex="1"
											 data-placeholder="Choose acompanyCode" class="" name="searchValueInfo">
											<option value="">--</option>
												<c:forEach var="moduleInfo" items= "${listModuleInfos}" >
													<option 
														<c:if test="${searchValueInfo==moduleInfo.moduleName}">selected="selected"</c:if>
													value="${moduleInfo.moduleName}">${moduleInfo.moduleName}</option>
												</c:forEach>
											</select>		
											
											<input class="m-wrap medium" size="10" name="searchValue" placeholder="<spring:message code='RoleName'></spring:message>"
											value="${searchValue}" type="text" />
										<button class="btn red">查询</button>
									</div>
									
								</div>	

								<table class="table table-striped table-bordered table-hover" id="user_grid">

									<thead>

										<tr>
											<th><spring:message code="role name"></spring:message></th>
											<th><spring:message code="mark"></spring:message></th>
											<th><spring:message code="moduleName"></spring:message></th>
											<th id="th_createtime" onclick="sortBy(this,'create_time');" class="sorting"><spring:message code="create time"></spring:message></th>
											<th><spring:message code="operation"></spring:message></th>
										</tr>

									</thead>
									<tbody>
										<c:forEach items="${list.resultList}" var="item" varStatus="status">
										
										<tr class="odd gradeX">
											<td>${item.roleName}</td>
											<td>${item.roleDesc}</td>
											<td>${item.moduleName}</td>
											<td>
												<c:if test="${!empty(item.createTime)}">
													<fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
												</c:if>
											</td>
											<td>
												<a  href="#" onclick="toEditPage(${item.moduleRoleId});" class="btn mini blue">
												<spring:message code="btn.common.edit"></spring:message></a>
												
												<a onclick="delRole(${item.moduleRoleId},'${item.roleName}');"
												href="#" class="btn mini red"><spring:message code="btn.common.delete"></spring:message></a> 
												
												<a  href="<%=request.getContextPath() %>/module/role/purview?id=${item.moduleRoleId}"  class="btn mini blue">
												<spring:message code="权限管理"></spring:message></a>
											</td>

										</tr>
										</c:forEach>
									</tbody>
									
								</table>
								
								<!-- 分页 -->
								<c:if test="${list.totalPages>1}">
									<div class="pagination" style="float:right">
										<ul>
											<li><a href="javascript:void();"><spring:message
														code="total"></spring:message>：${list.totalRows}</a></li>
											<li <c:if test="${list.currentPage==1}">class="disabled"</c:if>>
												<c:if test="${list.currentPage>1}">
													<a href="javascript:toListPage(${list.currentPage-1});"><spring:message
														code="previous page"></spring:message></a>
												</c:if>
												<c:if test="${list.currentPage==1}">
													<a href="#"><spring:message
														code="previous page"></spring:message></a>
												</c:if>
											</li>
											<c:forEach begin="1" end="${list.totalPages}" var="item">
											<c:if test="${item < 4 || item==list.currentPage || item==list.currentPage+1 || item==list.currentPage+2 || item + 3 > list.totalPages }">
											<li <c:if test="${list.currentPage==item }">class="active"</c:if>><a href="javascript:toListPage(${item});">${item}</a></li></c:if>
											</c:forEach>
											<li <c:if test="${list.currentPage==list.totalPages}">class="disabled"</c:if>>
												<c:if test="${list.currentPage==list.totalPages}">
													<a href="#"><spring:message
														code="next page"></spring:message></a>
												</c:if>
												<c:if test="${list.currentPage!=list.totalPages}">
													<a href="javascript:toListPage(${list.currentPage+1})"><spring:message
														code="next page"></spring:message> </a>
												</c:if>
											</li>
										</ul>
									</div>
								</c:if>
							</div>


						</div>
			</div>


		</div>
		
		</form>
		

	
 --%>
 
 
 
 <div class="page-content">
		<div class="page-header">
			<!-- <h1>
				jqGrid
				<small>
					<i class="icon-double-angle-right"></i>
					Dynamic tables and grids using jqGrid plugin
				</small>
			</h1> -->
			<button class="btn btn-xs btn-primary" onclick="add();" id="newBtn">New</button>
			<button class="btn btn-xs btn-primary" onclick="edit();" id="editBtn">Edit</button>
			<button class="btn btn-xs btn-primary" onclick="delUser();" id="deleteBtn">Delete</button>
			<button class="btn btn-xs btn-primary" onclick="rolePur();" id="rolePur">权限管理</button>
		</div>
		
		
		<div class="row">
			<div class="col-xs-12">
			<div class="form-group">
				角色名:<input type="text" id="searchId" maxlength="30"  class="m-wrap" />
				模块名称:<select tabindex="1" data-placeholder="Choose acompanyCode" class="m-wrap" id="searchValueInfo" name="searchValueInfo" style="width: 150px">
					<option value="">--</option>
						<c:forEach var="moduleInfo" items= "${listModuleInfos}" >
							<option 
								<c:if test="${searchValueInfo==moduleInfo.moduleName}">selected="selected"</c:if>value="${moduleInfo.moduleName}">${moduleInfo.moduleName}</option>
						</c:forEach>
						</select>		
				<button class="btn btn-xs btn-primary" onclick="search();" id="searchBtn">Search</button>
			</div>
			
			<!-- 列表 -->
			<table id="grid-table"></table>
			<!-- 分页 -->
			<div id="grid-pager"></div>
		</div>
		</div>
	</div>

</body>